home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / src / cmds / gdb-4.5 / dist / gdb / umax-xdep.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-03-03  |  3.6 KB  |  138 lines

  1. /* umax host stuff.
  2.    Copyright (C) 1986, 1987, 1989, 1991 Free Software Foundation, Inc.
  3.  
  4. This file is part of GDB.
  5.  
  6. This program is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2 of the License, or
  9. (at your option) any later version.
  10.  
  11. This program is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with this program; if not, write to the Free Software
  18. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "defs.h"
  21. #include "frame.h"
  22. #include "inferior.h"
  23.  
  24. #include <sys/param.h>
  25. #include <sys/dir.h>
  26. #include <signal.h>
  27. #include <sys/ioctl.h>
  28. #include <fcntl.h>
  29.  
  30. #include "gdbcore.h"
  31. #include <sys/ptrace.h>
  32. #define PTRACE_ATTACH PT_ATTACH
  33. #define PTRACE_DETACH PT_FREEPROC
  34.  
  35. #include <sys/file.h>
  36. #include <sys/stat.h>
  37.  
  38. /* Work with core dump and executable files, for GDB. 
  39.    This code would be in core.c if it weren't machine-dependent. */
  40.  
  41. void
  42. core_file_command (filename, from_tty)
  43.      char *filename;
  44.      int from_tty;
  45. {
  46.   int val;
  47.   extern char registers[];
  48.  
  49.   /* Discard all vestiges of any previous core file
  50.      and mark data and stack spaces as empty.  */
  51.  
  52.   if (corefile)
  53.     free (corefile);
  54.   corefile = 0;
  55.  
  56.   if (corechan >= 0)
  57.     close (corechan);
  58.   corechan = -1;
  59.  
  60.   data_start = 0;
  61.   data_end = 0;
  62.   stack_start = STACK_END_ADDR;
  63.   stack_end = STACK_END_ADDR;
  64.  
  65.   /* Now, if a new core file was specified, open it and digest it.  */
  66.  
  67.   if (filename)
  68.     {
  69.       filename = tilde_expand (filename);
  70.       make_cleanup (free, filename);
  71.       
  72.       if (have_inferior_p ())
  73.     error ("To look at a core file, you must kill the inferior with \"kill\".");
  74.       corechan = open (filename, O_RDONLY, 0);
  75.       if (corechan < 0)
  76.     perror_with_name (filename);
  77.       /* 4.2-style (and perhaps also sysV-style) core dump file.  */
  78.       {
  79.     struct ptrace_user u;
  80.     int reg_offset;
  81.  
  82.     val = myread (corechan, &u, sizeof u);
  83.     if (val < 0)
  84.       perror_with_name (filename);
  85.     data_start = exec_data_start;
  86.  
  87.     data_end = data_start + u.pt_dsize;
  88.     stack_start = stack_end - u.pt_ssize;
  89.     data_offset = sizeof u;
  90.     stack_offset = data_offset + u.pt_dsize;
  91.     reg_offset = 0;
  92.  
  93.     bcopy (&u.pt_aouthdr, &core_aouthdr, sizeof (AOUTHDR));
  94.     printf ("Core file is from \"%s\".\n", u.pt_comm);
  95.     if (u.pt_signal > 0)
  96.       printf ("Program terminated with signal %d, %s.\n",
  97.             u.pt_signal,
  98.             u.pt_signal < NSIG
  99.             ? sys_siglist[u.pt_signal]
  100.             : "(undocumented)");
  101.  
  102.     /* Read the register values out of the core file and store
  103.        them where `read_register' will find them.  */
  104.  
  105.     {
  106.       register int regno;
  107.  
  108.       for (regno = 0; regno < NUM_REGS; regno++)
  109.         {
  110.           char buf[MAX_REGISTER_RAW_SIZE];
  111.  
  112.           val = lseek (corechan, register_addr (regno, reg_offset), 0);
  113.           if (val < 0)
  114.         perror_with_name (filename);
  115.  
  116.            val = myread (corechan, buf, sizeof buf);
  117.           if (val < 0)
  118.         perror_with_name (filename);
  119.           supply_register (regno, buf);
  120.         }
  121.     }
  122.       }
  123.       if (filename[0] == '/')
  124.     corefile = savestring (filename, strlen (filename));
  125.       else
  126.     {
  127.       corefile = concat (current_directory, "/", filename, NULL);
  128.     }
  129.  
  130.       set_current_frame ( create_new_frame (read_register (FP_REGNUM),
  131.                         read_pc ()));
  132.       select_frame (get_current_frame (), 0);
  133.       validate_files ();
  134.     }
  135.   else if (from_tty)
  136.     printf ("No core file now.\n");
  137. }
  138.